import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QFormLayout
from PyQt5.QtWidgets import QPushButton, QLineEdit, QTextEdit, QMessageBox


def delete_click():
    print("删除用户")
    # QMessageBox.information(w, "删除用户", "删除第一个用户名")
    result = QMessageBox.question(
        w,
        "提示",
        "确认删除用户吗",
        buttons=QMessageBox.Yes | QMessageBox.Cancel,
        defaultButton=QMessageBox.Cancel,
    )
    if result == QMessageBox.Yes:
        print("删除用户")
    else:
        print("取消")


if __name__ == "__main__":
    # 1. 创建应用程序
    app = QApplication(sys.argv)

    # 2. 创建窗口
    w = QWidget()
    # 创建标题
    w.setWindowTitle("对话框")
    # w.resize(400, 300)

    # 创建垂直布局：vertical；创建水平布局：horizon
    root_layout = QHBoxLayout(w)
    button = QPushButton("删除用户")
    root_layout.addWidget(button)
    button.clicked.connect(delete_click)

    w.setLayout(root_layout)

    # 3. 显示窗口
    w.show()

    # 4. 等待APP停止
    sys.exit(app.exec_())
